package com.trover.myapplication.core.http

import com.trover.myapplication.core.util.PrefUtils
import okhttp3.Interceptor
import okhttp3.Response
import java.util.*

class SaveCookiesInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val response = chain.proceed(request)
        if (response.headers("set-cookie").isNotEmpty()) {
            val cookies =
                HashSet(response.headers("set-cookie"))
            PrefUtils.setHashSet(RetrofitConstants.COOKIE, cookies)
        }
        return response
    }
}